package com.hue.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机名
    public static final String EXCHANGE_NAME = "topic_exchange";

    //队列名
    public static final String QUEUE1 = "topic_queue1";
    public static final String QUEUE2 = "topic_queue2";

    //声明交换机
    @Bean
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    //声明队列1
    @Bean
    public Queue queue1(){
        return QueueBuilder.durable(QUEUE1).build();
    }

    //声明队列2
    @Bean
    public Queue queue2(){
        return QueueBuilder.durable(QUEUE2).build();
    }

    //将队列1绑定到交换机
    @Bean
    public Binding binding1(Exchange exchange,Queue queue1){
        return BindingBuilder.bind(queue1).to(exchange).with("user.select").noargs();
    }

    //将队列绑定到交换机
    @Bean
    public Binding binding2(Exchange exchange,Queue queue2){
        return BindingBuilder.bind(queue2).to(exchange).with("user.*").noargs();
    }
}
